{include file="public/header" /}



<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.ds_pointprod}</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

    <form id="pointprod_form" method="post" enctype="multipart/form-data" >
        <table class="ds-default-table">
            <thead>
            <tr class="space">
                <th colspan="3">{$Think.lang.admin_pointprod_baseinfo}</th>
            </tr>
            </thead>
            <tbody>
            <tr class-"noborder">
            <th class="required" style="line-height:normal; border-top: 1px dotted #CBE9F3;"><label for="">{$Think.lang.admin_pointprod_goods_image}:</label></th>
            <td colspan="2" class="required"><label class="validation" for="goodsname">{$Think.lang.admin_pointprod_goods_name}:</label></td>
            </tr>
            <tr class="noborder">
                <th rowspan="6" class="picture">
                    <div class="size-200x200">
                        <span class="thumb size-200x200">
                            <i></i>
                            <img src="{$prod_info.pgoods_image}"  onload="javascript:ResizeImage(this,200,200);"/></span>
                    </div>
                </th>
                <td class="vatop rowform"><input type="text" name="goodsname" id="goodsname" class="txt" value="{$prod_info.pgoods_name}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label class="validation" for="goodsserial">{$Think.lang.admin_pointprod_goods_serial}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="goodsserial" id="goodsserial" class="txt" value="{$prod_info.pgoods_serial}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label class="validation" for="goodsprice">{$Think.lang.admin_pointprod_goods_price}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="goodsprice" id="goodsprice" class="txt" value="{$prod_info.pgoods_price}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label class="validation" for="goodspoints">{$Think.lang.admin_pointprod_goods_points}:</label></td>
            </tr>
            <tr class="noborder">
                <th style="line-height:normal;"><span class="type-file-box">
              <input name="goods_images" type="file" class="type-file-file" id="goods_images" size="30" hidefocus="true" ds_type="change_goods_image">
                    <input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='上传' class='type-file-button' />
            </span> </th>
                <td class="vatop rowform"><input type="text" name="goodspoints" id="goodspoints" class="txt" value="{$prod_info.pgoods_points}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <th class="required"><label for="goodstag">{$Think.lang.admin_pointprod_goods_tag}:</label></th>
                <td colspan="2" class="required"><label class="validation" for="goodsstorage">{$Think.lang.admin_pointprod_goods_storage}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="goodstag" id="goodstag" class="txt" value="{$prod_info.pgoods_tag}"/></td>
                <td class="vatop rowform"><input type="text" name="goodsstorage" id="goodsstorage" class="txt" value="{$prod_info.pgoods_storage}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="space">
                <th colspan="10">{$Think.lang.admin_pointprod_requireinfo}</th>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_limittip}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <input type="radio" name="islimit" id="islimit_1" value="1" {if $prod_info.pgoods_islimit == 1}checked=checked{/if}  onclick="showlimit();"/>
                    <label for="">{$Think.lang.admin_pointprod_limit_yes}</label>
                    <input type="radio" name="islimit" id="islimit_0" value="0" {if $prod_info.pgoods_islimit == 0}checked=checked{/if} onclick="showlimit();"/>
                    <label>{$Think.lang.admin_pointprod_limit_no}</label></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            </tbody>
            <tbody id="limitnum_div">
            <tr>
                <td colspan="10" class="required"><label for="limitnum">{$Think.lang.admin_pointprod_limitnum}: </label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="limitnum" id="limitnum" class="txt" value="{$prod_info.pgoods_limitnum}"/></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            </tbody>
            <tbody>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_limittimetip}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="radio" name="islimittime" id="islimittime_1" value="1" {if $prod_info.pgoods_islimittime == 1}checked=checked{/if} onclick="showlimittime();"/>
                    <label for="islimittime_1">{$Think.lang.admin_pointprod_limittime_yes}</label>
                    <input type="radio" name="islimittime" id="islimittime_0" value="0" {if $prod_info.pgoods_islimittime == 0}checked=checked{/if} onclick="showlimittime();"/>
                    <label for="islimittime_0">{$Think.lang.admin_pointprod_limittime_no}</label></td>
                <td class="vatop tips" colspan="10"></td>
            </tr>
            </tbody>
            <tbody name="limittime_div">
            <tr>
                <td class="required">{$Think.lang.ds_start_time}:
                    </label></td>
                <td colspan="9" class="required"><label>{$Think.lang.ds_end_time}: </label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="starttime" id="starttime" class="txt date" style="width:100px;" value="{if $prod_info.pgoods_starttime}{$prod_info.pgoods_starttime|date='Y-m-d'} {else /}{:date('Y-m-d')}{/if}"/>
                    {$Think.lang.admin_pointprod_time_day}
                    <select id="starthour" name="starthour" style="width:50px; margin-left: 8px; _margin-left: 4px;">
                        {foreach name="hourarr" item="item"}
                        <option value="{$item}" <?php if ($item == @date('H',$prod_info.pgoods_starttime)){ echo 'selected'; } ?>>{$item}</option>
                       {/foreach}
                    </select>
                    {$Think.lang.admin_pointprod_time_hour}</td>
                <td class="vatop rowform"><input type="text" name="endtime" id="endtime" class="txt date" style="width:100px;" value="{if $prod_info.pgoods_endtime}{$prod_info.pgoods_endtime|date='Y-m-d'}{else}{:date('Y-m-d')}{/if}"/>
                    {$Think.lang.admin_pointprod_time_day}
                    <select id="endhour" name="endhour" style="width:50px; margin-left: 8px; _margin-left: 4px;">
                        {foreach name="hourarr" item="item"}
                        <option value=" {$item}" <?php if ($item == @date('H',$prod_info.pgoods_endtime)){ echo 'selected'; } ?>>{$item}</option>
                        {/foreach}
                    </select>
                    {$Think.lang.admin_pointprod_time_hour}</td>
                <td colspan="9" class="vatop tips">&nbsp;</td>
            </tr>
            </tbody>
            <tbody>
            <tr>
                <td colspan="3" class="required"><label>{$Think.lang.admin_pointprod_limitgrade}:</label></td>
            </tr>
            <tr class="noborder">
                <td>
                    <select name="limitgrade">
                        {if $member_grade}
                        {foreach name="member_grade" item="v"}
                        <option {if $prod_info.pgoods_limitmgrade == $v.level}selected='selected'{/if} value="{$v.level}">V{$v.level}</option>
                        {/foreach}
                        {/if}
                    </select>
                </td>
                <td colspan="2" class="vatop tips">{$Think.lang.admin_pointprod_limitgrade_tips}</td>
            </tr>
            </tbody>
            <tbody>
            <tr class="space">
                <th colspan="10">{$Think.lang.admin_pointprod_stateinfo}</th>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_isshow}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff"><label for="showstate_1" class="cb-enable {if $prod_info.pgoods_show == '1'}selected{/if}"><span>{$Think.lang.admin_pointprod_yes}</span></label>
                    <label for="showstate_0" class="cb-disable {if $prod_info.pgoods_show == '0'}selected{/if}"><span>{$Think.lang.admin_pointprod_no}</span></label>
                    <input id="showstate_1" name="showstate" {if $prod_info.pgoods_show == '1'}checked=checked{/if} value="1" type="radio">
                    <input id="showstate_0" name="showstate" {if $prod_info.pgoods_show == '0'}checked=checked{/if} value="0" type="radio"></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_iscommend}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff"><label for="commendstate_1" class="cb-enable {if $prod_info.pgoods_commend == '1'}selected{/if}"><span>{$Think.lang.admin_pointprod_yes}</span></label>
                    <label for="commendstate_0" class="cb-disable {if $prod_info.pgoods_commend == '0'}selected{/if}"><span>{$Think.lang.admin_pointprod_no}</span></label>
                    <input id="commendstate_1" name="commendstate" {if $prod_info.pgoods_commend == '1'}checked=checked{/if} value="1" type="radio">
                    <input id="commendstate_0" name="commendstate" {if $prod_info.pgoods_commend == '0'}checked=checked{/if} value="0" type="radio"></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            </tbody>
            <tbody id="forbidreason_div">
            <tr>
                <td colspan="10" class="required"><label for="forbidreason">{$Think.lang.admin_pointprod_forbidreason}: </label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><textarea name="forbidreason" id="forbidreason" rows="6">{$prod_info.pgoods_close_reason}</textarea></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            </tbody>
            <tbody>
            <tr class="space">
                <th colspan="10">{$Think.lang.admin_pointprod_seoinfo}</th>
            </tr>
            <tr>
                <td colspan="10" class="required"><label for="keywords">{$Think.lang.admin_pointprod_seokey}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="keywords" id="keywords" class="txt" value="{$prod_info.pgoods_keywords}"/></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_seodescription}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><textarea name="description" rows="6">{$prod_info.pgoods_description}</textarea></td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            </tbody>
            <tbody>
            <tr class="space">
                <th colspan="10">{$Think.lang.admin_pointprod_otherinfo}</th>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_sort}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="sort" id="sort" class="txt" value="{$prod_info.pgoods_sort}"/></td>
                <td colspan="10" class="vatop tips">{$Think.lang.admin_pointprod_sorttip}</td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_edit_addtime}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">{$prod_info.pgoods_addtime|date="Y-m-d"}</td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_edit_viewnum}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">{$prod_info.pgoods_view}</td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="10" class="required"><label>{$Think.lang.admin_pointprod_edit_salenum}:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">{$prod_info.pgoods_salenum}</td>
                <td colspan="10" class="vatop tips"></td>
            </tr>
            <tr class="space">
                <th colspan="10">{$Think.lang.admin_pointprod_descriptioninfo}</th>
            </tr>
            <tr>
                <td colspan="10">
                    {:build_editor(['name'=>'pgoods_body','content'=>htmlspecialchars_decode($prod_info.pgoods_body)])}
                    <textarea name="pgoods_body" id="pgoods_body"></textarea>
            </tr>
            <tr>
                <td colspan="10" class="required">{$Think.lang.admin_pointprod_uploadimg}:</td>
            </tr>
            <tr class="noborder">
                <td colspan="3" id="divComUploadContainer"><input type="file" multiple="multiple" id="fileupload" name="fileupload" /></td>
            </tr>
            <tr>
                <td colspan="10" class="required">{$Think.lang.admin_pointprod_uploadimg_complete}:</td>
            </tr>
            <tr class="noborder">
                <td colspan="10"><ul id="thumbnails" class="thumblists">
                    {notempty name="file_upload"}
                    {foreach name="file_upload" item="v"}
                    <li id="{$v.upload_id}" class="picture" >
                        <input type="hidden" name="file_id[]" value={$v.upload_id}" />
                        <div class="size-64x64"><span class="thumb"><i></i><img src="{:ds_get_pic(ATTACH_POINTPROD,$v.file_name)}" alt="{$v.file_name}" onload="javascript:ResizeImage(this,64,64);"/></span></div>
                        <p><span><a href="javascript:insert_editor('{:ds_get_pic(ATTACH_POINTPROD,$v.file_name)}');">{$Think.lang.admin_pointprod_uploadimg_add}</a></span><span><a href="javascript:del_file_upload('{$v.upload_id}');">{$Think.lang.ds_del}</a></span></p>
                    </li>
                    {/foreach}
                    {/notempty}
                </ul></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="15"><input class="btn" type="submit" value="{$Think.lang.ds_submit}"/></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-file-upload/jquery.fileupload.js"></script>
<script>

    function showlimit(){
        var islimit = $(":radio[name=islimit]:checked").val();
        if(islimit == '1'){
            $("#limitnum_div").show();
        }else{
            $("#limitnum_div").hide();
            $("#limitnum").val('1');//为了减少提交表单的验证，所以添加一个虚假值
        }
    }
    function showforbidreason(){
        var forbidstate = $(":radio[name=forbidstate]:checked").val();
        if(forbidstate == '1'){
            $("#forbidreason_div").show();
        }else{
            $("#forbidreason_div").hide();
        }
    }
    function showlimittime(){
        var islimit = $(":radio[name=islimittime]:checked").val();
        if(islimit == '1'){
            $("[name=limittime_div]").show();
        }else{
            $("[name=limittime_div]").hide();
            $("#starttime").val("{$Think.TIMESTAMP|date='Y-m-d'}");
            $("#endtime").val("{$Think.TIMESTAMP|date='Y-m-d'}");
        }
    }
    $(function(){
        $("#goods_images").change(function () {
            $("#textfield1").val($("#goods_images").val());
        });
        showlimit();
        showforbidreason();
        showlimittime();

        $('#starttime').datepicker({dateFormat: 'yy-mm-dd'});
        $('#endtime').datepicker({dateFormat: 'yy-mm-dd'});
        $('#pointprod_form').validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parent().parent().prev().find('td:first'));
            },
            rules : {
                goodsname : {
                    required   : true
                },
                goodsprice    : {
                    required  : true,
                    number    : true,
                    min       : 0
                },
                goodspoints : {
                    required   : true,
                    digits     : true,
                    min		   :0
                },
                goodsserial : {
                    required   : true
                },
                goodsstorage  : {
                    required  : true,
                    digits    : true
                },
                limitnum  : {
                    required   : true,
                    digits     : true,
                    min        : 0
                },
                starttime  : {
                    required  : true,
                    date      : false
                },
                endtime  : {
                    required  : true,
                    date      : false
                },
                sort : {
                    required  : true,
                    digits    : true,
                    min		  :0
                }
            },
            messages : {
                goodsname  : {
                    required   : '{$Think.lang.admin_pointprod_add_goodsname_error}'
                },
                goodsprice : {
                    required: '{$Think.lang.admin_pointprod_add_goodsprice_null_error}',
                    number  : '{$Think.lang.admin_pointprod_add_goodsprice_number_error}',
                    min     : '{$Think.lang.admin_pointprod_add_goodsprice_number_error}'
                },
                goodspoints : {
                    required: '{$Think.lang.admin_pointprod_add_goodspoint_null_error}',
                    digits     : '{$Think.lang.admin_pointprod_add_goodspoint_number_error}',
                    min		   : '{$Think.lang.admin_pointprod_add_goodspoint_number_error}'
                },
                goodsserial:{
                    required : '{$Think.lang.admin_pointprod_add_goodsserial_null_error}'
                },
                goodsstorage : {
                    required: '{$Think.lang.admin_pointprod_add_storage_null_error}',
                    digits  : '{$Think.lang.admin_pointprod_add_storage_number_error}'
                },
                limitnum : {
                    required: '{$Think.lang.admin_pointprod_add_limitnum_error}',
                    digits  : '{$Think.lang.admin_pointprod_add_limitnum_digits_error}',
                    min		: '{$Think.lang.admin_pointprod_add_limitnum_digits_error}'
                },
                starttime  : {
                    required: '{$Think.lang.admin_pointprod_add_limittime_null_error}'
                },
                endtime  : {
                    required: '{$Think.lang.admin_pointprod_add_limittime_null_error}'
                },
                sort : {
                    required: '{$Think.lang.admin_pointprod_add_sort_null_error}',
                    digits  : '{$Think.lang.admin_pointprod_add_sort_number_error}',
                    min		: '{$Think.lang.admin_pointprod_add_sort_number_error}'
                }
            }
        });

        // 替换图片
        $('#fileupload').each(function(){
            $(this).fileupload({
                dataType: 'json',
                url: ADMINSITEURL+'/Pointprod/pointprod_pic_upload/item_id/{$prod_info.pgoods_id}',
                done: function (e,data) {
                    if(data != 'error'){
                        add_uploadedfile(data.result);
                    }
                }
            });
        });
    });
    function add_uploadedfile(file_data)
    {
        var newImg = '<li id="' + file_data.file_id + '" class="picture">' +
            '<input type="hidden" name="file_id[]" value="' + file_data.file_id + '" />' +
            '<div class="size-64x64">' +
            '<span class="thumb">' +
            '<i></i>' +
            '<img src="' + file_data.file_path + '" alt="' + file_data.file_name + '" width="64px" height="64px"/>' +
            '</span></div>' +
            '<p>' +
            '<span>' +
            '<a href="javascript:insert_editor(\'' + file_data.file_path + '\');">{$Think.lang.admin_pointprod_uploadimg_add}</a>' +
            '</span>' +
            '<span><a href="javascript:del_file_upload(' + file_data.file_id + ');">{$Think.lang.ds_del}</a></span>' +
            '</p>' +
            '</li>';
        $('#thumbnails').prepend(newImg);
    }
    function insert_editor(file_path){
        ue.execCommand('insertimage', {src:file_path});
    }
    function del_file_upload(file_id)
    {
        layer.confirm('{$Think.lang.ds_ensure_del}', {
            btn: ['{$Think.lang.ds_ok}', '{$Think.lang.ds_cancel}'],
            title: false,
        }, function () {
            $.get("{:url('Pointprod/ajaxdelupload')}",{file_id:+ file_id}, function(result){
                if(result){
                    $('#' + file_id).remove();
                    layer.msg('{$Think.lang.ds_common_del_succ}');
                }else{
                    layer.alert('{$Think.lang.admin_pointprod_delfail}');
                }
            });
        });
    }
</script>
